package com.test.mapper;

import com.test.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapperAnnotation {

    @Insert("insert into user(name, age, email) values (#{name}, #{age}, #{email})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertUser(User user);

    @Select("select * from user")
    List<User> queryUserList();

    @Update("<script>" +
            "update user set name = #{name}, age = #{age} " +
            "<if test=\"email != '' and email != null\">, email = #{email}</if>" +
            " where id = #{id}" +
            "</script>")
    void updateUserById(User user);

    @Delete("<script>" +
            "delete from user\n" +
            "        <where>\n" +
            "            <if test=\"id != '' and id != null\">\n" +
            "                id = #{id}\n" +
            "            </if>\n" +
            "        </where>" +
            "</script>")
    void deleteUserById(@Param("id") Integer id);
}
